package leetcode_1_200;

import node.TreeNode;

import java.util.ArrayList;
import java.util.List;

public class LeeCode_114 {
    public static void main(String[] args) {
        TreeNode ans = new TreeNode(1, new TreeNode(2, new TreeNode(3), new TreeNode(4)),
                new TreeNode(5, null, new TreeNode(6)));
        flatten(ans);
    }
    private static void flatten(TreeNode root) {
        if (root == null)
            return;
        List<TreeNode> list = new ArrayList<>();
        f(root, list);
        for (int i = 0; i < list.size() - 1; i++) {
            list.get(i).left = null;
            list.get(i).right = list.get(i + 1);
        }
    }
    private static void f(TreeNode node, List<TreeNode> list){
        if (node == null)
            return;
        list.add(node);
        f(node.left, list);
        f(node.right, list);
    }
}
